import 'package:dio/dio.dart';
import 'package:wu_you/data/repository/user_repository.dart';
import 'package:wu_you/model/user/team_model.dart';
import 'package:wu_you/model/user/user_model.dart';
import 'package:wu_you/state/bloc/http_bloc.dart';

///获取收货地址
class AddressListBloc extends HttpBloc<List<AddressModel>>{
  @override
  Future<List<AddressModel>> obtainData(HttpEvent event) {
    if (event is PageSizeHttpEvent) {
      return UserRepository().getAddressList();
    }
    return Future.error(DioError(error: "参数错误",requestOptions: null));
  }
}


class UserInfoBloc extends HttpBloc<UserInfoModel> {
  UserInfoBloc() : super();
  final UserRepository _userRepository = UserRepository();
  @override
  Future<UserInfoModel> obtainData(HttpEvent event) async {
    UserInfoModel userInfo = await _userRepository.getUserInfo();
    return userInfo;
  }
}




///默认收货地址
class DefaultAddressBloc extends HttpBloc<AddressModel> {
  DefaultAddressBloc() : super();
  @override
  Future<AddressModel> obtainData(HttpEvent event) {
    return UserRepository().getDefaultAddress();
  }
}


///收货地址列表
class ReceiveAddressBloc extends HttpBloc<List<AddressModel>> {
  ReceiveAddressBloc() : super();

  @override
  Future<List<AddressModel>> obtainData(HttpEvent event) {
    return UserRepository().getAddressList();
  }
}


///团队信息
class TeamInfoBloc extends HttpBloc<TeamInfoModel> {
  TeamInfoBloc() : super();
  final UserRepository _userRepository = UserRepository();
  @override
  Future<TeamInfoModel> obtainData(HttpEvent event) async {
    TeamInfoModel team = await _userRepository.getUserTeam();
    return team;
  }
}



///用户流水信息
class FundsListBloc extends HttpBloc<List<FundsListModel>> {
  @override
  Future<List<FundsListModel>> obtainData(HttpEvent event) {
    if (event is FundsListEvent) {
      return UserRepository().getFundsList(genre: event.genre, page: event.page, limit: event.size);
    }
    return UserRepository().getFundsList();
  }
}

class PointsListBloc extends HttpBloc<List<PointsSetModel>> {
  @override
  Future<List<PointsSetModel>> obtainData(HttpEvent event) {
    if (event is PageSizeHttpEvent) {
      return UserRepository().getPointsList();
    }
    return Future.error(DioError(error: "参数错误",requestOptions: null));
  }
}


///用户流水信息事件
class FundsListEvent extends PageSizeHttpEvent {
  final String genre;

  FundsListEvent(this.genre, int page, {int size = 10}) : super(page, size);

  @override
  List<Object> get props => [genre, page, size];
}



///提现信息获取
class WithdrawInfoBloc extends HttpBloc<WithdrawInfo> {
  WithdrawInfoBloc() : super();
  @override
  Future<WithdrawInfo> obtainData(HttpEvent event) {
    return UserRepository().getWithdrawInfo();
  }
}

///提现记录
class WithdrawRecordBloc extends HttpBloc<List<WithdrawRecord>> {
  WithdrawRecordBloc() : super();
  @override
  Future<List<WithdrawRecord>> obtainData(HttpEvent event) {
    if (event is PageSizeHttpEvent) {
      return UserRepository().getWithdrawList(page: event.page,limit: event.size);
    }
    return Future.error(DioError(error: "请求错误", requestOptions: null));
  }
}